package com.woniu.dao;

import com.woniu.dto.DynamicCommentDto;
import com.woniu.dto.DynamicPost;
import com.woniu.pojo.Dynamic;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DynamicMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Dynamic record);

    int insertSelective(Dynamic record);

    Dynamic selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Dynamic record);

    int updateByPrimaryKeyWithBLOBs(Dynamic record);

    int updateByPrimaryKey(Dynamic record);

    @Select(value = "select cd.*,pi.url,pu.name from community_dynamic cd,person_image pi,person_user pu where cd.cd_user_id = pu.id and pu.id = pi.person_user_id and cd_type = #{type} order by cd_favor desc")
    List<DynamicPost> selectByType(Integer type, @Param("currentPage") Integer page, @Param("pageSize") Integer num);

    @Select(value = "select cdc.*,pu.name from community_dynamic_comment cdc,person_user pu where cdc.cdc_dynamic_id=#{dynamicId} and cdc.cdc_user_id = pu.id")
    List<DynamicCommentDto> selectById(Integer dynamicId);

    @Select(value = "select url from person_image where person_user_id = #{userId}")
    String selectUserPicById(Integer userId);

    @Select(value = "select cd.*,pi.url,pu.name from community_dynamic cd,person_image pi,person_user pu where cd.cd_user_id = pu.id and pu.id = pi.person_user_id and cd.id = #{dynamicId}")
    DynamicPost selectDynamicById(Integer dynamicId);

    @Select(value = "select cd.*,pi.url,pu.name from community_dynamic cd,person_image pi,person_user pu where cd.cd_user_id = pu.id and pu.id = pi.person_user_id order by cd_favor desc")
    List<DynamicPost> selectByPage(@Param("currentPage") Integer page, @Param("pageSize") Integer num);
}